﻿<%@ Page Title="Rapporter" Language="C#" MasterPageFile="~/masterpage.master" AutoEventWireup="true" CodeBehind="SurveyReports.aspx.cs" Inherits="UL360Admin.Survey.SurveyReports" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="headcontent" runat="server">
    <link href="<%= Page.ResolveUrl("~/Styles/Survey/SurveyStyles.css") %>" rel="Stylesheet" type="text/css" />
    <link href="<%= Page.ResolveUrl("~/Styles/Survey/ReportsStyles.css") %>" rel="Stylesheet" type="text/css" />
    <link href="<%= Page.ResolveUrl("~/Styles/Survey/jquery-ui-1.10.2+.custom.css") %>" rel="Stylesheet" type="text/css" /> 

    <script type="text/javascript">

        //Hides the checkbox if there is no selected survey version in dropdown list
        $(function () {
            if (document.getElementById("CheckBoxState").value == "0") {
                document.getElementById("ThCheckAll").style.display = "none";
            }
        });

        //Messages when viewing report
        function reportPostBack(msg) {
            $("#dialog-modal").dialog("close");
            var returnMessage = JSON.parse(msg);
            if (returnMessage.Status == 0) {

                form = document.createElement('FORM');
                form.name = 'ReportContentForm';
                form.method = 'POST';

                tb = document.createElement('INPUT');
                tb.type = 'HIDDEN';
                tb.name = 'ShowPdf';
                tb.value = 'true';
                form.appendChild(tb);

                tb = document.createElement('INPUT');
                tb.type = 'HIDDEN';
                tb.name = 'pdfContent';
                tb.value = returnMessage.ReportContent;
                form.appendChild(tb);

                document.body.appendChild(form);
                form.submit();
            }
            else {
                $("#dialog-modal-message").html("Ett fel uppstod när rapporten skulle hämtas.\n" +
                    "Var god försök igen eller kontakta support med följande id:\n" +
                    returnMessage.ErrorTicket).dialog("open");
            }
        }

        //Messages when sending report
        function mailReportPostBack(msg) {
            $("#dialog-modal-mail").dialog("close");
            var returnMessage = JSON.parse(msg);
            //Sent to all
            if (returnMessage.Status == 0) {
                $("#dialog-modal-message").html("Rapporten har skickats.").dialog("open");
            }
            //Sent to none
            else if (returnMessage.Status == 10) {
                $("#dialog-modal-message").html("Rapporten kunde inte skickas till någon handledare, antingen var " +
                    "inte e-postadresserna giltiga eller så har ett tekniskt fel uppstått, var god försök igen eller kontakta support.").dialog("open");
            }
            //Sent to some
            else if (returnMessage.Status == 11) {
                var message = "Rapporten kunde inte skickas till följande handledare: <br /><br />";
                for(var i = 0; i < returnMessage.NonReceived.length; i++)
                {
                    message += returnMessage.NonReceived[i] + "<br />";
                }
                message += "<br />Detta kan bero på att e-postadresserna inte är korrekt utformade.";
                $("#dialog-modal-message").html(message).dialog("open");
            }
            //Other error
            else {
                $("#dialog-modal-message").html("Ett fel uppstod när rapporten skulle skickas.\n" +
                    "Var god försök igen eller kontakta support med följande id:\n" +
                    returnMessage.ErrorTicket).dialog("open");
            }
        }

        //Dialog window for progressbar
        $(function () {
            $("#dialog-modal").dialog({
                autoOpen: false,
                modal: true,
                height: "auto",
                width: "auto"
            });
        });

        //Dialog window for progressbar
        $(function () {
            $("#dialog-modal-mail").dialog({
                autoOpen: false,
                modal: true,
                height: "auto",
                width: "auto"
            });
        });

        //Dialog window for messages
        $(function () {
            $("#dialog-modal-message").dialog({
                autoOpen: false,
                height: 200,
                width: 250,
                modal: true
            });
        });

        function showReportClick(courseId) 
        {
            formType = document.getElementById("FormType").value;

            $("#dialog-modal").dialog("open");
            $.ajax({
                type: "POST",
                url: '<%= Page.ResolveUrl(UL360SurveyCommon.Constants.REQUEST_HANDLER_URL) %>?ShowReport=true&FormType=' + formType + '&CourseId=' + courseId,
                data: '',
                success: reportPostBack,
                dataType: "html"
            });

            event.returnValue = false;
            return false;
        }

        function sendReportClick(courseId) {
            formType = document.getElementById("FormType").value;

            $("#dialog-modal-mail").dialog("open");
            $.ajax({
                type: "POST",
                url: '<%= Page.ResolveUrl(UL360SurveyCommon.Constants.REQUEST_HANDLER_URL) %>?ShowReport=true&FormType=' + formType + '&CourseId=' + courseId + "&SendMail=true",
                data: '',
                success: mailReportPostBack,
                dataType: "html"
            });

            event.returnValue = false;
            return false;
        }

    </script>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">

<div class="content-container">

    <asp:SiteMapPath ID="SiteMapPath1" runat="server" CssClass="siteMapPath"></asp:SiteMapPath>

    <h3><asp:Label ID="ReportListTitle" runat="server" Text="Kursutvärderingsrapporter del 1"></asp:Label></h3>

    <h4><asp:Label ID="InformationLabel" runat="server"></asp:Label></h4>
    <asp:Label ID="ErrorLabel" runat="server" CssClass="survey-warning" />
    <asp:HiddenField ID="CheckBoxState" ClientIDMode="Static" runat="server" Value="0" />

    <div>
        <asp:Label ID="Label1" runat="server" CssClass="text" Text="Välj enkätversion i listan för att kunna jämföra kurser med varandra"></asp:Label>
        <br />
        <asp:DropDownList OnSelectedIndexChanged="Page_Load" CssClass="dropdown" AutoPostBack="true" ClientIDMode="Static" ID="SurveyVersions" runat="server"></asp:DropDownList>
        <br />
        <br />
    </div>
    <div>
        <asp:Button ID="CompareCourses" ClientIDMode="Static" runat="server" OnClick="CompareCourses_Click" Text="Jämför kurser" ToolTip="Klicka här för att visa en jämförelserapport (PDF) med ikryssade kurser" />
    </div>
    
    <asp:HiddenField ID="FormType" ClientIDMode="Static" runat="server" />
    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <ContentTemplate>
            <asp:ListView ID="ReportsListView" ViewStateMode="Disabled" runat="server">
                <LayoutTemplate>
                    <table id="reportsTable" class="grid reports-table" cellspacing="0" rules="all" border="1">
                        <tr class="gridheaderstyle">
                            <th><asp:LinkButton ClientIDMode="Static" ID="SortByCourseName" OnCommand="ReportsListView_Sorting" CommandArgument="organisation" runat="server">Kursnamn</asp:LinkButton></th>
                            <th>
                                <asp:LinkButton ClientIDMode="Static" ID="SortByEndDate" OnCommand="ReportsListView_Sorting" CommandArgument="slutdatum" runat="server">Slutdatum</asp:LinkButton>
                                <asp:LinkButton ClientIDMode="Static" ID="SortByExtDate" OnCommand="ReportsListView_Sorting" CommandArgument="slutdatum" runat="server">Fördjupningsdag</asp:LinkButton>
                            </th>
                            <th>
                                <asp:LinkButton ClientIDMode="Static" ID="SortByMainTutor" OnCommand="ReportsListView_Sorting" CommandArgument="Handledare" runat="server">Huvudhandledare</asp:LinkButton></th>
                            <th>Övriga handledare</th>
                            <th>Medelvärde</th>
                            <th>&nbsp;</th>
                            <th>&nbsp;</th>
                            <th id="ThCheckAll">
                                <asp:CheckBox ClientIDMode="Static" ID="CheckAll" ViewStateMode="Enabled" AutoPostBack="true" OnCheckedChanged="CheckAll_CheckedChanged" runat="server" ToolTip="Kryssa i denna ruta för att markera/avmarkera alla poster i listan" />
                            </th>
                            <blockquote>
                 <asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
              </blockquote>
                        </tr>
                        <tbody id="itemPlaceholder" runat="server"></tbody>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
            
                    <asp:HiddenField ID="courseId" runat="server" Value='<%# Eval("kursid") %>' />
                    <tr class="gridrowstyle">

                        <td>
                            <asp:Label ID="courseName" runat="server" Text='<%# Eval("organisation") %>' /></td>
                        <td><asp:Label CssClass="sortByEndDate" ID="endDate" runat="server" /></td>
                        <td><asp:Label CssClass="sortByMainTutor"  runat="server" ID="mainTutor"></asp:Label></td>
                        <td><asp:Label runat="server" ID="tutors"></asp:Label></td>
                        <td><asp:Label ID="average" runat="server"></asp:Label></td>
                        <td><a href="<%= HttpContext.Current.Request.Url %>" class="show-report-button" onclick='showReportClick(<%# Eval("kursid") %>)'>Visa rapport</a></td>
                        <td><a href="<%= HttpContext.Current.Request.Url %>" class="mail-report-button" onclick='sendReportClick(<%# Eval("kursid") %>)'>Skicka rapport till handledare</a></td>
                        <% if(SurveyVersions.Items.Count != 0 && SurveyVersions.SelectedItem.Value != "0") { %>
                                <td><asp:CheckBox ID="CheckBox" ClientIDMode="Static" runat="server" /></td>
                        <% }%>
                        
                    </tr>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <asp:HiddenField ID="courseId" runat="server" Value='<%# Eval("kursid") %>' />
                    <tr>

                        <td>
                            <asp:Label ID="courseName" runat="server" Text='<%# Eval("organisation") %>' /></td>
                        <td><asp:Label CssClass="sortByEndDate" ID="endDate" runat="server" /></td>
                        <td><asp:Label CssClass="sortByMainTutor"  runat="server" ID="mainTutor"></asp:Label></td>
                        <td><asp:Label runat="server" ID="tutors"></asp:Label></td>
                        <td><asp:Label ID="average" runat="server"></asp:Label></td>
                        <td><a href="<%= HttpContext.Current.Request.Url %>" class="show-report-button" onclick='showReportClick(<%# Eval("kursid") %>)'>Visa rapport</a></td>
                        <td><a href="<%= HttpContext.Current.Request.Url %>" class="mail-report-button" onclick='sendReportClick(<%# Eval("kursid") %>)'>Skicka rapport till handledare</a></td>
                        <% if(SurveyVersions.Items.Count != 0 && SurveyVersions.SelectedItem.Value != "0") { %>
                            <td><asp:CheckBox ID="CheckBox" ClientIDMode="Static" runat="server" /></td>
                        <% }%>

                    </tr>
                </AlternatingItemTemplate>
            </asp:ListView>
        </ContentTemplate> 
    </asp:UpdatePanel>
</div>
<div id="dialog-modal" title="">Hämtar...<br /><br /><img alt="Hämtar..." src='<%= Page.ResolveClientUrl("~/Images/loader.gif") %>' /></div>
<div id="dialog-modal-mail" title="">Skickar...<br /><br /><img alt="Skickar..." src='<%= Page.ResolveClientUrl("~/Images/loader.gif") %>' /></div>
<div id="dialog-modal-message" title="Meddelande"></div>

</asp:Content>
